import { Button, View,Image } from "@tarojs/components"
import { Current } from "@tarojs/runtime"
import Taro, { useDidShow } from "@tarojs/taro"
import { isError } from "lodash"
import moment from "moment"
import { Component, useEffect, useState } from "react"
import WeChat from "../img/WeChat.png";
import shareCard from "../img/shareCard.png";
import { AtCard, AtFloatLayout, AtIcon } from "taro-ui"

// import WeChat from "../../pages/postBar/img/WeChat.png";
// import shareCard from "../../pages/postBar/img/shareCard.png";

const Content_1 = () => {

    // 建议在页面初始化时把 getCurrentInstance() 的结果保存下来供后面使用，
    // 而不是频繁地调用此 API
    const [newList, setList] = useState([])
    //数据库中所有的数据的保存
    const [listAll, setListAll] = useState([])
    
    const [isOpen, setOpen] = useState(false);
    const [isRight, setRight] = useState(true);
    //通过decodeURIComponent(Current.router.params.userList)的类型来判断是否是通过路由跳进来的
    useDidShow(() => {
        // if (typeof decodeURIComponent(Current.router.params.userList)==="string") {
        //     console.log("执行的if")
        Taro.cloud.callFunction({
            name: "comments",
            data: {
                $url: "commentsToday",
                date: moment().format('YYYY-MM-DD')//用来取出当天发布的信息
            }
        }).then(res => {
            setListAll(res.result.res.data)
        })
        // } else {
        //     console.log("执行的else")
        //     let data = JSON.parse(decodeURIComponent(Current.router.params.userList))
        //     setList(data)
        // }

    })
    console.log("newlist_1:", listAll)
    
    const handleClick3 = () => {
        Taro.navigateTo({
            url: '/pages/details/shareCard/shareCard'
        })
    }

    const handleClick4 = () => {
        Taro.navigateTo({
            url: '/pages/postBar/comment/comment',
        });
    };
    const changeOpen = () => {
        setOpen(true)
    }
    const changeRight = () => {
        setRight(!isRight)
    }
    const handleClick=()=>{
        
    }
    //从数据库中得到所有的评论信息
    const showAll = listAll.map(item => (
        <View>
            <AtCard
                note={item === undefined ? null : item.author}
                extra={item === undefined ? null : item.content_time}
                title={item === undefined ? null : item.title}
                thumb={item === undefined ? null : item.picture[0]}
                onClick={()=>{handleClick()}}
            >
                {item === undefined ? null : item.contents}
            </AtCard>
        </View>
    ))

    return (
        <View>
            {showAll}
        </View>
    )
}
export default Content_1